<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap namespace="ProductType"
	xmlns="http://ibatis.apache.org/mapping" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<alias>
		<typeAlias alias="ProductType" type="Domain.ProductType" />
	</alias>

	<resultMaps>
		<resultMap id="FullResultMap" class="ProductType">
			<result property="productTypeID" column="productTypeID" dbType="Int"/>
			<result property="productTypeName" column="productTypeName" dbType="NVarChar"/>
			<result property="parentID" column="parentID" dbType="Int"/>
			<result property="productTypeLevel" column="productTypeLevel" dbType="Int"/>
			<result property="orderId" column="orderId" dbType="Int"/>
		</resultMap>
	</resultMaps>
	
	<statements>

		<select id="GetCount" resultClass="System.Int32">
			SELECT count(*) FROM [dbo].[productType]
		</select>
		
		<select id="GetCountByCondition" parameterClass="Hashtable" resultClass="System.Int32" extends="GetCount">
			WHERE $condition$
		</select>
		
		<select id="FindAll" resultClass="ProductType">
			SELECT * 
			FROM [dbo].[productType]
		</select>
		
		<select id="GetModel" parameterClass="ProductType" resultClass="ProductType" extends="FindAll">
			WHERE
				([productType].[productTypeID] = #productTypeID,dbType=Int#)
		</select>

		<insert id="Insert" parameterClass="ProductType">
			INSERT INTO [dbo].[productType] (
				
				[productTypeName] , 
				[parentID] , 
				[productTypeLevel] , 
				[orderId]
			) VALUES (
				
				 #productTypeName,dbType=NVarChar# , 
				 #parentID,dbType=Int# , 
				 #productTypeLevel,dbType=Int# , 
				 #orderId,dbType=Int#
			)
		</insert>

		<update id="Update" parameterClass="ProductType">
			UPDATE [dbo].[productType] SET
				 [productTypeName] = #productTypeName,dbType=NVarChar#
				, [parentID] = #parentID,dbType=Int#
				, [productTypeLevel] = #productTypeLevel,dbType=Int#
				, [orderId] = #orderId,dbType=Int#
			WHERE
				([productTypeID] = #productTypeID,dbType=Int#)
		</update>

		<delete id="Delete" parameterClass="ProductType">
			DELETE FROM [dbo].[productType]
			WHERE
				([productTypeID] = #productTypeID,dbType=Int#)
		</delete>

		<select id="GetModelsByCondition" parameterClass="Hashtable" resultClass="ProductType">
			SELECT $columnNames$ FROM [dbo].[productType] where $condition$
		</select>
		
		<select id="GetModelsByConditionByPager" parameterClass="Hashtable" resultClass="ProductType">
			SELECT * FROM 
			(select $columnNames$,row_number() over(order by $orderBy$) as rno from [dbo].[productType] where $condition$) t 
			<![CDATA[
			where t.rno>#startNo# and t.rno<=#endNo#
			]]>
		</select>
		
	</statements>
</sqlMap>
